﻿using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using MediaSage.Lib.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MediaSageLibTest
{
    [TestClass]
    public class TernaryTreeTest
    {
        [TestMethod]
        public void TernaryTreeTestAddNodes()
        {
            TernaryTree tt=new TernaryTree();
            tt.Add("dog");
            tt.Add("cat");
            tt.Add("dog");
            tt.Add("cow");
            tt.Add("seal");

            Assert.AreEqual(true, tt.Contains("dog"), "Expected true, got false");
            Assert.AreEqual(false, tt.Contains("foo"), "Expected false, got true");
        }

        [TestMethod]
        public void TernaryTreeStoreAndLoad()
        {
            TernaryTree tt = new TernaryTree();
            tt.Add("dog");
            tt.Add("cat");
            tt.Add("dog");
            tt.Add("cow");
            tt.Add("seal");
            tt.Save("test.tree.bin");
            TernaryTree loadedTree;
            Stream stream = null;
            stream = File.Open("test.tree.bin", FileMode.Open);
            var bFormatter = new BinaryFormatter();
            loadedTree = (TernaryTree)bFormatter.Deserialize(stream);
            stream.Close();
            Assert.AreEqual(true, tt.Contains("dog"), "Expected true, got false");
            Assert.AreEqual(false, tt.Contains("foo"), "Expected false, got true");
        }
    }
}
